package fun.tan90.solon.config;

import fun.tan90.solon.entity.Res;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.exception.StatusException;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;

@Component
public class AppFilter implements Filter {
    @Override
    public void doFilter(Context ctx, FilterChain chain) throws Throwable {
        try {
            chain.doFilter(ctx);
        } catch (StatusException e) {
            ctx.render(Res.failure(e.getCode(), e.getMessage()));
        } catch (Throwable e) {
            ctx.render(Res.failure(500, "服务端运行出错"));
        }
    }
} 